package com.javabasic.algorithm.leetcode;

/**
 * @Author xiongmin
 * @Description //TODO
 * @Date 2020/7/1 20:28
 * @Version 1.0
 **/
public class MaximumSubarray {

    public int maxSubArray(int[] nums) {
        int len = nums.length;
        int result = Integer.MIN_VALUE;
        int tag = 0;
        for (int i = 0; i < len; i++) {
            tag += nums[i];
            result = Math.max(tag,result);
            if (tag < 0) {
                tag = 0;
            }
        }
        return result;
    }
}
